package com.trkj.controller;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.trkj.pojos.CcElectornicPrescribe;
import com.trkj.pojos.CcHospitalElectronic;
import com.trkj.pojos.CcPatient;
import com.trkj.pojos.YzrGrantMedDet;
import com.trkj.service.YzrGrantMedService;
import com.trkj.vo.Result;
import com.trkj.vo.YzrGrantMedVo;
import com.trkj.vo.YzrSaleMedicineListVo;
import com.trkj.vo.YzrSaleMedicineVo;

@Controller
public class YzrGrantMedController {

	@Autowired
	private YzrGrantMedService yzrGrantMedService;
	
	
	
	@RequestMapping("/to_grantMedYzr")
	public String toGrant(){
		return "yzr_grant_med";
	}
	
	//住院未处理的处方单
	@RequestMapping("/queryByNoSuccessYzr")
	public @ResponseBody List<CcHospitalElectronic> queryByNoSuccess(){
		return yzrGrantMedService.queryByNoSuccess();
	}
	
	//根据处方号找到住院id,然后再找到病人名字
	@RequestMapping("/findBingRenNameYzr")
	public @ResponseBody String findBingRenName(long chufangId){
		return yzrGrantMedService.findBingRenName(chufangId);
	}
	
	//根据住院处方id找到下面所有的药品
	@RequestMapping("/queryAllMedDetYzrYzr")
	public @ResponseBody List<YzrSaleMedicineVo> queryAllMedDet(String chufangId){
		System.err.println("chufangId:"+chufangId);
		return yzrGrantMedService.queryAllMedDet(new BigDecimal(chufangId));
	}
	
	//提交买药数据
	@RequestMapping("/addGrantYzr")
	public @ResponseBody Result addGrant(YzrSaleMedicineListVo medList,Long staffId,String yaofangkind,String yf,String zje,
									long chufangId,String br){
		System.err.println("staffId:"+staffId);
		System.err.println("yaofangkind:"+yaofangkind);
		System.err.println("yf:"+yf);
		System.err.println("zje:"+zje);
		System.err.println("chufangId:"+chufangId);
		System.err.println("br:"+br);
		System.err.println("medList:"+medList.getMedList().size());
		
		String r = yzrGrantMedService.addGrant(medList, staffId, yaofangkind, yf, zje, chufangId, br);
		return new Result(true,r);
	}
	
	//分页查询发药信息
	@RequestMapping("/queryAllGrantstockYzr")
	public @ResponseBody Map<String,Object> queryAllGrantstock(int page, int rows){
		return yzrGrantMedService.queryAllGrantstock(page, rows);
	}
	
	//根据id查询发药信息
	@RequestMapping("/queryGrantByIdYzr")
	public @ResponseBody YzrGrantMedVo queryGrantById(String grantMedId){
		return yzrGrantMedService.queryGrantById(grantMedId);
	}
	
	//根据id查询发药详情
	@RequestMapping("/queryDetByGrantIdYzr")
	public @ResponseBody List<YzrGrantMedDet> queryDetByGrantId(String grantMedId){
		return yzrGrantMedService.queryDetByGrantId(grantMedId);
	}
}
